//
//  BaseUIExt.m
//  BaiduTravel
//
//  Created by liangqiaozhong on 13-7-15.
//  Copyright (c) 2013年 Baidu.com. All rights reserved.
//

#import "BaseUIExt.h"
#import <QuartzCore/QuartzCore.h>

@implementation UIView(ColorExt)

-(void) setBackgroundColorWithImage:(UIImage *)image
{
    if ( [image isKindOfClass:[UIImage class]] ) {
        self.layer.contents = (id) image.CGImage;
    }
}

@end

@implementation UIViewController(PresentViewController)

- (void) presentViewControllerWithCompatibility:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    static BOOL isIOS5 = NO;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        isIOS5 = [[[UIDevice currentDevice] systemVersion] compare:@"5.0" options:NSNumericSearch] != NSOrderedAscending;
    });
    if ( isIOS5 )
        [self presentViewController:viewControllerToPresent animated:flag completion:completion];
    else
        [self presentModalViewController:viewControllerToPresent animated:flag];
}


- (void) presentViewControllerWithCompatibility:(UIViewController *)viewControllerToPresent animated:(BOOL)flag
{
    [self presentViewControllerWithCompatibility:viewControllerToPresent animated:flag completion:nil];
}

- (void)dismissViewControllerAnimatedWithCompatibility:(BOOL)flag completion: (void (^)(void))completion
{
    static BOOL isIOS5 = NO;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        isIOS5 = [[[UIDevice currentDevice] systemVersion] compare:@"5.0" options:NSNumericSearch] != NSOrderedAscending;
    });
    if ( isIOS5 )
        [self dismissViewControllerAnimated:flag completion:completion];
    else
        [self dismissModalViewControllerAnimated:flag];
}


- (void)dismissViewControllerAnimatedWithCompatibility:(BOOL)flag
{
    [self dismissViewControllerAnimatedWithCompatibility:flag completion:nil];
}


@end
